#include <game/flow/SelectorFactory.h>
#include <game/flow/Selector.h>

#include <system/assert.h>

ARELLO_GAME_NAMESPACE_DECL_START
namespace flow {

SelectorFactory::SelectorFactory()
{ }

SelectorFactory::SelectorFactory(const SelectorFactory& rhs)
	: selectors(rhs.selectors)
{
}

SelectorFactory::~SelectorFactory()
{ }

const SelectorFactory& SelectorFactory::operator=(const SelectorFactory& rhs)
{
	if (&rhs != this)
		this->selectors = rhs.selectors;

	return *this;
}

void SelectorFactory::Register(const std::string& name, SelectorCreator creator)
{
	std::pair<std::map<std::string, SelectorCreator>::iterator, bool> insertResult =
		this->selectors.insert(std::make_pair(name, creator));

	LIBA_ASSERT(insertResult.second);
}

std::auto_ptr<Selector> SelectorFactory::Create(const std::string& name) const
{
	std::map<std::string, SelectorCreator>::const_iterator i =
		this->selectors.find(name);

	if (i != this->selectors.end())
		return i->second();

	return std::auto_ptr<Selector>();
}

} // namespace flow
ARELLO_GAME_NAMESPACE_DECL_END